package gold.digger;

import gold.utils.InputUtil;

import java.util.PriorityQueue;
import java.util.*;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LCIT1714 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int[] smallestK(int[] arr, int k) {
            int[] vec = new int[k];
            if (k == 0) { // 排除 0 的情况
                return vec;
            }

            PriorityQueue<Integer> queue = new PriorityQueue<Integer>(new Comparator<Integer>() {
                public int compare(Integer num1, Integer num2) {
                    return num2 - num1;
                }
            });

            for (int i = 0; i < k; ++i) {
                queue.offer(arr[i]);
            }

            for (int i = k; i < arr.length; ++i) {
                if (queue.peek() > arr[i]) {
                    queue.poll();
                    queue.offer(arr[i]);
                }
            }
            for (int i = 0; i < k; ++i) {
                vec[i] = queue.poll();
            }
            return vec;
        }
    }


    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LCIT1714 an = new LCIT1714();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
